package largemodel

import (
	"context"
	"github.com/jinzhu/copier"
	"large-model-platform-backend/internal/svc"
	"large-model-platform-backend/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListLogic {
	return &ListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ListLogic) List(req *types.Request) (resp *types.LargeModelResp, err error) {
	// todo: add your logic here and delete this line
	model := l.svcCtx.LargeModel
	all, err := model.FindAll(l.ctx)
	var models []types.LargeModelData
	for _, largeModel := range all {
		//t := types.LargeModelData{
		//	ID: largeModel.ID.Hex(),
		//	LargeModel: types.LargeModel{
		//		Type:     largeModel.Type,
		//		NickName: largeModel.NickName,
		//		Number:   largeModel.Number,
		//	},
		//	DeepSeek: types.IDeepSeek{
		//		Url:    largeModel.DeepSeek.Url,
		//		Method: largeModel.DeepSeek.Method,
		//		ApiKey: largeModel.DeepSeek.ApiKey,
		//		Model:  largeModel.DeepSeek.Model,
		//	},
		//	KiMi: types.IKiMi{
		//		Url:         largeModel.KiMi.Url,
		//		Method:      largeModel.KiMi.Method,
		//		ApiKey:      largeModel.KiMi.ApiKey,
		//		Model:       largeModel.KiMi.Model,
		//		Temperature: largeModel.KiMi.Temperature,
		//	},
		//}
		t := types.LargeModelData{}
		// todo 还待是这个好，使用反射
		copier.Copy(&t, &largeModel)
		t.ID = largeModel.ID.Hex()
		models = append(models, t)
	}

	return &types.LargeModelResp{
		Result: types.Result{
			Code:      200,
			Message:   "",
			ExtInfo:   "",
			Timestamp: 0,
		},
		Data: models,
	}, nil
}
